package com.ash;

import JavaAPI.CofInfo;
import JavaAPI.HttpsPostRequest;
import JavaAPI.Purchase;
import com.ash.service.TransactionService;

/**
 * Credential on file transactions are available to Canada Integrations only
 * <p>
 * 在最初存储持卡人凭证时，请务必遵循以下规定：
 * <p>
 * 获取持卡人的卡片验证数字（CVD）。
 * 在初次交易中，发卡行ID将不带值发送。
 * 支付信息字段的值始终为0。
 * 在存储持卡人数据之前，必须获得持卡人的同意。
 * 只有在财务交易获得批准后，才能存储持卡人数据
 * <p>
 * Note:Credential on file transactions are available to Canada Integrations only.
 *
 * @author ash
 */
public class TestPurchaseCof {


    public static void main(String[] args) {
        TransactionService transactionService = TransactionService.getInstance();

        HttpsPostRequest mpgReq = transactionService.getHttpsPostRequest();

        Purchase purchase = getPurchase();

        mpgReq.setTransaction(purchase);

        mpgReq.send();

        transactionService.printResult(mpgReq);
    }


    private static Purchase getPurchase() {
        java.util.Date createDate = new java.util.Date();
        String order_id = "Test" + createDate.getTime();
        String amount = "1.00";
        String pan = "5454545454545454";
        String expdate = "2501"; //YYMM format

        // 交易类别
        String crypt = "7";
        Purchase purchase = new Purchase();
        purchase.setOrderId(order_id);
        purchase.setAmount(amount);
        purchase.setPan(pan);
        purchase.setExpdate(expdate);
        purchase.setCryptType(crypt);
        purchase.setDynamicDescriptor("123456");

        // optional 建议都加
        purchase.setCustId("ootdbuy");

        // 这些字段用来标识你打算在未来的交易中重复使用这张卡的信息
        CofInfo cofInfo = new CofInfo();
        cofInfo.setPaymentIndicator("U");
        cofInfo.setPaymentInformation("2");
        cofInfo.setIssuerId("139X3130ASCXAS9");

        purchase.setCofInfo(cofInfo);

        return purchase;
    }
}
